package multithreading;
//runnable实现
public class SecondThread implements Runnable{
    public void run()
    {
        for(int i=0;i<100;i++)
        {//实现runnable接口时，获取当前线程，只能用Thread.currentThread()方法
            System.out.println(Thread.currentThread().getName()+" "+i);
        }
    }

    public static void main(String[] args) {
        for(int i=0;i<100;i++)
        {
            System.out.println(Thread.currentThread().getName()+" "+i);
            if(i==20)
            {
                SecondThread st=new SecondThread();
                //通过new Thread（target,name）创建新线程
                new Thread(st,"1").start();
                new Thread(st,"2").start();
            }
        }
    }
}
